package com.tiantianyuegou.app;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

import com.trouble.framework.pay.alipay.Alipay;
import com.trouble.framework.pay.alipay.AlipayConfiguration;
import com.trouble.framework.pay.wechat.WechatPay;
import com.trouble.framework.pay.wechat.WechatPayConfiguration;
import com.umeng.socialize.PlatformConfig;
import com.tiantianyuegou.http.ApiDefine;
import com.tiantianyuegou.http.SPHelper;
import com.tiantianyuegou.pay.PayConstants;

public class SysApplication extends Application {


    public List<Activity> mlist = new LinkedList<Activity>();
    private static SysApplication instance;

    private SysApplication() {

    }

    @Override
    public void onCreate() {
        super.onCreate();
        SPHelper.getInstance(this);
//        payInit();
    }

    public synchronized static SysApplication getInstance() {
        if (null == instance) {
            instance = new SysApplication();
        }
        return instance;
    }

    public void payInit(){
        AlipayConfiguration configuration = new AlipayConfiguration.Builder().setPartner(PayConstants.ALIPAY_PARTNER)
                .setSeller(PayConstants.ALIPAY_SELLER).setRsaPublic(PayConstants.ALIPAY_RSA_PUBLIC)
                .setRsaPrivate(PayConstants.ALIPAY_RSA_PRIVATE).setNotifyUrl(ApiDefine.SERVER_URL).build();
        Alipay.getInstance().init(configuration);
        WechatPayConfiguration wechatConfiguration = new WechatPayConfiguration.Builder()
                .setAppId(PayConstants.WECHAT_APPID).setAppKey(PayConstants.WECHAT_APPKEY)
                .setMchId(PayConstants.WECHAT_MCHID).setNotifyUrl(ApiDefine.SERVER_URL).build();
        WechatPay.getInstance().init(wechatConfiguration);

    }

    public void shareInit(){
        //分享的各个平台的设置
        //qq和qq空间
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        //新浪微博
        PlatformConfig.setSinaWeibo("3166599476","29ca7176113218f149d629655031319d");
        //微信
        PlatformConfig.setWeixin("wxc41d2c99ab2f2fdc", "a03f12af96f4969bf0a46379cbf489bc");
    }

    public void addActivity(Activity activity) {
        mlist.add(activity);
    }

    public void exit() {
        try {
            for (Activity activity : mlist) {
                if (activity != null) {
                    activity.finish();
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            //System.exit(0);
        }
    }


    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }


}
